# coding: utf-8

class Solution:
    def isPalindrome(self, s: str) -> bool:
        import re
        # ss = s.replace(r'[a-z]', '')
        ss = re.sub(r'[^a-zA-Z0-9]', '', s).lower()
        def check(l, r, s):
            print((l, r),s[l:r])
            ll = len(s)
            while 0 <= l <= r < ll:
                print(s[l], s[r], s[l]!=s[r])
                if s[l] != s[r]:
                    return False
                l, r = l-1, r+1
            return True
        l = len(ss)-1
        if check(l//2, l//2+l%2, ss):
            return True
        return False


def op(l):
    solve = Solution()
    for i, s in enumerate(l):
        print('problem #%d'%(i+1))
        print('question: %s'%s)
        print('ans: %s'%solve.isPalindrome(s))


def main():
    q_list = []
    q_list.append('A man, a plan, a canal: Panama')
    q_list.append('race a car')
    q_list.append('ab')
    q_list.append('0p')
    op(q_list)


if __name__ == '__main__':
    main()
